﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BagItem : MonoBehaviour
{
    Weapon weapon;
    UISprite icon;
    private void Awake()
    {
        icon = transform.Find("Icon").GetComponent<UISprite>();
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }
    //给Item添加赋值weapon的方法

    public void Init(Weapon weapon)
    {
        this.weapon = weapon;
    }

    //删除Item的方法
    public void Clean()
    {
        this.weapon = null;
        icon.gameObject.SetActive(false);
    }

    //刷新Icon的方法
    public void Refresh()
    {
        //重置Icon位置
        icon.gameObject.transform.localPosition = Vector3.zero;
        //判断Icon是否获得weapon属性，用SetActive控制Icon是否显示
        if (weapon==null)
        {
            icon.gameObject.SetActive(false);
        }
        else
        {
            icon.gameObject.SetActive(true);
            //用Format更改Icon的精灵名字更改图片
            icon.spriteName = string.Format("item_{0}", weapon.id);
        }
       // icon.spriteName = string.Format("item_{0}", weapon.id);
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
